<template>
  <div
    :class="['tool-card', viewMode, { popular: tool.popular, hovered: isHovered }]"
    @click="$emit('openTool', tool)"
    @mouseenter="$emit('mouseenter', tool.id)"
    @mouseleave="$emit('mouseleave')"
    :style="{ '--tool-color': tool.color }"
  >
    <div class="card-inner">
      <div class="tool-icon">
        <!-- <i :class="tool.icon"></i> -->
        <img style="width: 100%; height: 100%" :src="tool.icon" alt="" srcset="" />
      </div>
      <div class="tool-content">
        <h3 class="tool-name">{{ tool.name }}</h3>
        <p class="tool-desc">{{ tool.description }}</p>
        <div class="tool-meta">
          <span class="tool-category">{{ getCategoryName(tool.category) }}</span>
        </div>
      </div>
      <div v-if="tool.popular" class="popular-badge"><i class="fas fa-star"></i> 热门</div>
      <div class="card-corner"></div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  tool: {
    type: Object,
    required: true
  },
  viewMode: {
    type: String,
    default: 'grid'
  },
  isHovered: {
    type: Boolean,
    default: false
  },
  categories: {
    type: Array,
    default: () => []
  }
})

defineEmits(['openTool', 'mouseenter', 'mouseleave'])

// 获取分类名称
const getCategoryName = (categoryId) => {
  const category = props.categories.find(cat => cat.id === categoryId)
  return category ? category.name : '未知'
}
</script>

<style scoped>
.tool-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 0;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transform-style: preserve-3d;
  perspective: 1000px;
}

.tool-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--tool-color), transparent);
  transform: scaleX(0);
  transition: transform 0.3s;
}

.tool-card:hover::before {
  transform: scaleX(1);
}

.card-inner {
  padding: 25px;
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.tool-card.grid {
  min-height: 200px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.tool-card.list {
  display: flex;
  align-items: center;
  padding: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.tool-card.list .card-inner {
  flex-direction: row;
  align-items: center;
  width: 100%;
  padding: 0;
}

.tool-card.list .tool-icon {
  margin-right: 20px;
  margin-bottom: 0;
}

.tool-card.list .tool-content {
  flex: 1;
}

.tool-card:hover {
  transform: translateY(-8px) rotateX(5deg);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.3);
}

.tool-card.hovered {
  transform: translateY(-5px) scale(1.02);
}

.tool-card.popular {
  border: 1px solid rgba(255, 215, 0, 0.3);
}

.tool-icon {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, var(--tool-color), rgba(255, 255, 255, 0.3));
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  color: white;
  font-size: 28px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.3s;
}

.tool-card:hover .tool-icon {
  transform: scale(1.1) rotate(5deg);
}

.tool-card.list .tool-icon {
  width: 50px;
  height: 50px;
  font-size: 20px;
  margin-bottom: 0;
}

.tool-content {
  flex: 1;
}

.tool-name {
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 18px;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tool-card.list .tool-name {
  margin-bottom: 5px;
}

.tool-desc {
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 15px;
}

.tool-card.list .tool-desc {
  margin-bottom: 0;
}

.tool-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tool-category {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.popular-badge {
  position: absolute;
  top: 15px;
  right: 15px;
  background: linear-gradient(135deg, #ffd700, #ffa500);
  color: #8b4513;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: bold;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.card-corner {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  border-bottom: 20px solid var(--tool-color);
  border-left: 20px solid transparent;
  opacity: 0.3;
  transition: all 0.3s;
}

.tool-card:hover .card-corner {
  border-bottom-width: 30px;
  border-left-width: 30px;
}

/* 列表视图特定样式 */
.tool-card.list .popular-badge {
  position: static;
  margin-left: 15px;
}

.tool-card.list .card-corner {
  display: none;
}
</style>